<?php
/*
Plugin Name: Demo Add table
Description: Plug in using insert or update  a tabledsfgsd
Author: Dxnguyen
Author URI: dxnguyen.com
Plugin URI:dxnguyen.com/plugins
Version: 1.0
*/

global $wp_version;
if(version_compare($wp_version,'3.0','<') ){
	exit('This plugin require Wordpress version 3.0 or higher. Please upgrade now.');
}

global $jal_db_version;
$jal_db_version = "1.0";

function create_table(){
	global $wpdb;
	$table_name= $wpdb->prefix."dxnguyen";
	if($wpdb->get_var('SHOW TABLES LIKE'.$table_name != $table_name) ){
	$sql = "CREATE TABLE $table_name (
									  id mediumint(9) NOT NULL AUTO_INCREMENT,
									  time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
									  name tinytext NOT NULL,
									  text text NOT NULL,
									  url VARCHAR(55) DEFAULT '' NOT NULL,
									  UNIQUE KEY id (id)
									);";	
	require_once(ABSPATH."wp-admin/includes/upgrade.php");
	dbDelta($sql);
	add_option( "TABLE CRON JOB");
	
	}
}
function delete_table(){
	global $wpdb;
	$table_name = $wpdb->prefix."dxnguyen";
	$wpdb->query("DROP TABLE IF EXISTS".$table_name);
}
///since 3.1 can't called
//register_activation_hook( __FILE__, 'create_table' );
//register_deactivation_hook( __FILE__, 'delete_table' );
////////////

//using this function for wordpress 3.1 or hieger
function jal_install_data() {
   global $wpdb;
   $welcome_name = "Mr. WordPress";
   $welcome_text = "Congratulations, you just completed the installation!";
   $table_name = $wpdb->prefix . "dxnguyen";
   $rows_affected = $wpdb->insert( $table_name, array( 'time' => current_time('mysql'), 'name' => $welcome_name, 'text' => $welcome_text ) );
}

/*function myplugin_update_db_check() {
    global $jal_db_version;
    if (get_site_option( 'jal_db_version' ) != $jal_db_version) {
        jal_install();
    }
}
add_action( 'plugins_loaded', 'myplugin_update_db_check' );*/